{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "import tushare as ts"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {
    "collapsed": true
   },
   "outputs": [],
   "source": [
    "cons = ts.get_apis()"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "1、获取股票行情"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-27</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.94</td>\n",
       "      <td>12.82</td>\n",
       "      <td>326738.0</td>\n",
       "      <td>420972320.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-26</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.82</td>\n",
       "      <td>12.88</td>\n",
       "      <td>12.78</td>\n",
       "      <td>252751.0</td>\n",
       "      <td>324110144.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-25</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.90</td>\n",
       "      <td>12.94</td>\n",
       "      <td>12.82</td>\n",
       "      <td>207438.0</td>\n",
       "      <td>267109744.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-24</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.84</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.95</td>\n",
       "      <td>12.82</td>\n",
       "      <td>272360.0</td>\n",
       "      <td>350864960.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-23</th>\n",
       "      <td>600000</td>\n",
       "      <td>13.02</td>\n",
       "      <td>12.84</td>\n",
       "      <td>13.03</td>\n",
       "      <td>12.83</td>\n",
       "      <td>315638.0</td>\n",
       "      <td>406941728.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              code   open  close   high    low       vol       amount\n",
       "datetime                                                             \n",
       "2017-10-27  600000  12.85  12.85  12.94  12.82  326738.0  420972320.0\n",
       "2017-10-26  600000  12.87  12.82  12.88  12.78  252751.0  324110144.0\n",
       "2017-10-25  600000  12.86  12.90  12.94  12.82  207438.0  267109744.0\n",
       "2017-10-24  600000  12.84  12.86  12.95  12.82  272360.0  350864960.0\n",
       "2017-10-23  600000  13.02  12.84  13.03  12.83  315638.0  406941728.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#股票日线行情\n",
    "df = ts.bar('600000', conn=cons, freq='D', start_date='2016-01-01', end_date='')\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "2、股票因子数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "      <th>tor</th>\n",
       "      <th>vr</th>\n",
       "      <th>ma5</th>\n",
       "      <th>ma10</th>\n",
       "      <th>ma20</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-27</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.94</td>\n",
       "      <td>12.82</td>\n",
       "      <td>326738.0</td>\n",
       "      <td>420972320.0</td>\n",
       "      <td>0.12</td>\n",
       "      <td>1.34</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.95</td>\n",
       "      <td>12.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-26</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.82</td>\n",
       "      <td>12.88</td>\n",
       "      <td>12.78</td>\n",
       "      <td>252751.0</td>\n",
       "      <td>324110144.0</td>\n",
       "      <td>0.09</td>\n",
       "      <td>0.84</td>\n",
       "      <td>12.89</td>\n",
       "      <td>12.96</td>\n",
       "      <td>12.95</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-25</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.90</td>\n",
       "      <td>12.94</td>\n",
       "      <td>12.82</td>\n",
       "      <td>207438.0</td>\n",
       "      <td>267109744.0</td>\n",
       "      <td>0.07</td>\n",
       "      <td>0.59</td>\n",
       "      <td>12.95</td>\n",
       "      <td>12.98</td>\n",
       "      <td>12.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-24</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.84</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.95</td>\n",
       "      <td>12.82</td>\n",
       "      <td>272360.0</td>\n",
       "      <td>350864960.0</td>\n",
       "      <td>0.10</td>\n",
       "      <td>0.84</td>\n",
       "      <td>12.98</td>\n",
       "      <td>13.00</td>\n",
       "      <td>12.96</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-23</th>\n",
       "      <td>600000</td>\n",
       "      <td>13.02</td>\n",
       "      <td>12.84</td>\n",
       "      <td>13.03</td>\n",
       "      <td>12.83</td>\n",
       "      <td>315638.0</td>\n",
       "      <td>406941728.0</td>\n",
       "      <td>0.11</td>\n",
       "      <td>1.03</td>\n",
       "      <td>13.01</td>\n",
       "      <td>13.02</td>\n",
       "      <td>12.96</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              code   open  close   high    low       vol       amount   tor  \\\n",
       "datetime                                                                      \n",
       "2017-10-27  600000  12.85  12.85  12.94  12.82  326738.0  420972320.0  0.12   \n",
       "2017-10-26  600000  12.87  12.82  12.88  12.78  252751.0  324110144.0  0.09   \n",
       "2017-10-25  600000  12.86  12.90  12.94  12.82  207438.0  267109744.0  0.07   \n",
       "2017-10-24  600000  12.84  12.86  12.95  12.82  272360.0  350864960.0  0.10   \n",
       "2017-10-23  600000  13.02  12.84  13.03  12.83  315638.0  406941728.0  0.11   \n",
       "\n",
       "              vr    ma5   ma10   ma20  \n",
       "datetime                               \n",
       "2017-10-27  1.34  12.85  12.95  12.95  \n",
       "2017-10-26  0.84  12.89  12.96  12.95  \n",
       "2017-10-25  0.59  12.95  12.98  12.96  \n",
       "2017-10-24  0.84  12.98  13.00  12.96  \n",
       "2017-10-23  1.03  13.01  13.02  12.96  "
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#带因子的行情\n",
    "df = ts.bar('600000', conn=cons, start_date='2016-01-01', end_date='', ma=[5, 10, 20], factors=['vr', 'tor'])\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "3、复权数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-27</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.94</td>\n",
       "      <td>12.82</td>\n",
       "      <td>326738.0</td>\n",
       "      <td>420972320.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-26</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.82</td>\n",
       "      <td>12.88</td>\n",
       "      <td>12.78</td>\n",
       "      <td>252751.0</td>\n",
       "      <td>324110144.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-25</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.90</td>\n",
       "      <td>12.94</td>\n",
       "      <td>12.82</td>\n",
       "      <td>207438.0</td>\n",
       "      <td>267109744.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-24</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.84</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.95</td>\n",
       "      <td>12.82</td>\n",
       "      <td>272360.0</td>\n",
       "      <td>350864960.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-23</th>\n",
       "      <td>600000</td>\n",
       "      <td>13.02</td>\n",
       "      <td>12.84</td>\n",
       "      <td>13.03</td>\n",
       "      <td>12.83</td>\n",
       "      <td>315638.0</td>\n",
       "      <td>406941728.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              code   open  close   high    low       vol       amount\n",
       "datetime                                                             \n",
       "2017-10-27  600000  12.85  12.85  12.94  12.82  326738.0  420972320.0\n",
       "2017-10-26  600000  12.87  12.82  12.88  12.78  252751.0  324110144.0\n",
       "2017-10-25  600000  12.86  12.90  12.94  12.82  207438.0  267109744.0\n",
       "2017-10-24  600000  12.84  12.86  12.95  12.82  272360.0  350864960.0\n",
       "2017-10-23  600000  13.02  12.84  13.03  12.83  315638.0  406941728.0"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#复权行情, adj=qfq(前复权)， hfq（后复权），默认None不复权\n",
    "df = ts.bar('600000', conn=cons, adj='qfq', start_date='2016-01-01', end_date='')\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "4、分钟和其它频度数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-27 15:00:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.85</td>\n",
       "      <td>4622.0</td>\n",
       "      <td>5941414.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:59:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.85</td>\n",
       "      <td>7610.0</td>\n",
       "      <td>9782857.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:58:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.85</td>\n",
       "      <td>1603.0</td>\n",
       "      <td>2061478.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:57:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.88</td>\n",
       "      <td>12.85</td>\n",
       "      <td>2667.0</td>\n",
       "      <td>3432980.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:56:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.86</td>\n",
       "      <td>2712.0</td>\n",
       "      <td>3488104.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:55:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.86</td>\n",
       "      <td>689.0</td>\n",
       "      <td>886152.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:54:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.85</td>\n",
       "      <td>1613.0</td>\n",
       "      <td>2073555.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:53:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.88</td>\n",
       "      <td>12.88</td>\n",
       "      <td>12.86</td>\n",
       "      <td>1362.0</td>\n",
       "      <td>1753090.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:52:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.85</td>\n",
       "      <td>1847.0</td>\n",
       "      <td>2375993.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:51:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.85</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.85</td>\n",
       "      <td>502.0</td>\n",
       "      <td>645482.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:50:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.86</td>\n",
       "      <td>923.0</td>\n",
       "      <td>1187002.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:49:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.86</td>\n",
       "      <td>1123.0</td>\n",
       "      <td>1445024.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:48:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.86</td>\n",
       "      <td>649.0</td>\n",
       "      <td>834725.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:47:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>361.0</td>\n",
       "      <td>464246.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27 14:46:00</th>\n",
       "      <td>600000</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.86</td>\n",
       "      <td>12.87</td>\n",
       "      <td>12.86</td>\n",
       "      <td>193.0</td>\n",
       "      <td>248291.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                       code   open  close   high    low     vol     amount\n",
       "datetime                                                                  \n",
       "2017-10-27 15:00:00  600000  12.86  12.85  12.87  12.85  4622.0  5941414.0\n",
       "2017-10-27 14:59:00  600000  12.86  12.87  12.87  12.85  7610.0  9782857.0\n",
       "2017-10-27 14:58:00  600000  12.87  12.86  12.87  12.85  1603.0  2061478.0\n",
       "2017-10-27 14:57:00  600000  12.86  12.86  12.88  12.85  2667.0  3432980.0\n",
       "2017-10-27 14:56:00  600000  12.86  12.86  12.87  12.86  2712.0  3488104.0\n",
       "2017-10-27 14:55:00  600000  12.86  12.86  12.87  12.86   689.0   886152.0\n",
       "2017-10-27 14:54:00  600000  12.86  12.86  12.87  12.85  1613.0  2073555.0\n",
       "2017-10-27 14:53:00  600000  12.86  12.88  12.88  12.86  1362.0  1753090.0\n",
       "2017-10-27 14:52:00  600000  12.85  12.86  12.87  12.85  1847.0  2375993.0\n",
       "2017-10-27 14:51:00  600000  12.86  12.85  12.87  12.85   502.0   645482.0\n",
       "2017-10-27 14:50:00  600000  12.86  12.86  12.87  12.86   923.0  1187002.0\n",
       "2017-10-27 14:49:00  600000  12.86  12.86  12.87  12.86  1123.0  1445024.0\n",
       "2017-10-27 14:48:00  600000  12.86  12.86  12.87  12.86   649.0   834725.0\n",
       "2017-10-27 14:47:00  600000  12.86  12.86  12.86  12.86   361.0   464246.0\n",
       "2017-10-27 14:46:00  600000  12.86  12.86  12.87  12.86   193.0   248291.0"
      ]
     },
     "execution_count": 17,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#分钟数据, 设置freq参数，分别为1min/5min/15min/30min/60min，D(日)/W(周)/M(月)/Q(季)/Y(年)\n",
    "df = ts.bar('600000', conn=cons, freq='1min', start_date='2016-01-01', end_date='')\n",
    "df.head(15)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "指数行情"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>amount</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-27</th>\n",
       "      <td>000300</td>\n",
       "      <td>3992.55</td>\n",
       "      <td>4021.97</td>\n",
       "      <td>4024.46</td>\n",
       "      <td>3991.35</td>\n",
       "      <td>1266728.0</td>\n",
       "      <td>1.529748e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-26</th>\n",
       "      <td>000300</td>\n",
       "      <td>3980.05</td>\n",
       "      <td>3993.58</td>\n",
       "      <td>4013.60</td>\n",
       "      <td>3973.55</td>\n",
       "      <td>1298954.0</td>\n",
       "      <td>1.704886e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-25</th>\n",
       "      <td>000300</td>\n",
       "      <td>3958.17</td>\n",
       "      <td>3976.95</td>\n",
       "      <td>3978.09</td>\n",
       "      <td>3954.00</td>\n",
       "      <td>882054.0</td>\n",
       "      <td>1.068203e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-24</th>\n",
       "      <td>000300</td>\n",
       "      <td>3926.23</td>\n",
       "      <td>3959.40</td>\n",
       "      <td>3959.50</td>\n",
       "      <td>3922.03</td>\n",
       "      <td>930581.0</td>\n",
       "      <td>1.201921e+11</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-23</th>\n",
       "      <td>000300</td>\n",
       "      <td>3930.89</td>\n",
       "      <td>3930.80</td>\n",
       "      <td>3936.27</td>\n",
       "      <td>3920.66</td>\n",
       "      <td>814849.0</td>\n",
       "      <td>1.002809e+11</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              code     open    close     high      low        vol  \\\n",
       "datetime                                                            \n",
       "2017-10-27  000300  3992.55  4021.97  4024.46  3991.35  1266728.0   \n",
       "2017-10-26  000300  3980.05  3993.58  4013.60  3973.55  1298954.0   \n",
       "2017-10-25  000300  3958.17  3976.95  3978.09  3954.00   882054.0   \n",
       "2017-10-24  000300  3926.23  3959.40  3959.50  3922.03   930581.0   \n",
       "2017-10-23  000300  3930.89  3930.80  3936.27  3920.66   814849.0   \n",
       "\n",
       "                  amount  \n",
       "datetime                  \n",
       "2017-10-27  1.529748e+11  \n",
       "2017-10-26  1.704886e+11  \n",
       "2017-10-25  1.068203e+11  \n",
       "2017-10-24  1.201921e+11  \n",
       "2017-10-23  1.002809e+11  "
      ]
     },
     "execution_count": 27,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#指数日行情, 设置asset='INDEX'\n",
    "df = ts.bar('000300', conn=cons, asset='INDEX', start_date='2016-01-01', end_date='')\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "5、港股数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-27</th>\n",
       "      <td>00981</td>\n",
       "      <td>10.800000</td>\n",
       "      <td>11.040001</td>\n",
       "      <td>11.200001</td>\n",
       "      <td>10.780001</td>\n",
       "      <td>613583</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-26</th>\n",
       "      <td>00981</td>\n",
       "      <td>10.840000</td>\n",
       "      <td>10.760000</td>\n",
       "      <td>11.140000</td>\n",
       "      <td>10.700001</td>\n",
       "      <td>387966</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-25</th>\n",
       "      <td>00981</td>\n",
       "      <td>10.820001</td>\n",
       "      <td>10.840000</td>\n",
       "      <td>10.980000</td>\n",
       "      <td>10.680000</td>\n",
       "      <td>258851</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-24</th>\n",
       "      <td>00981</td>\n",
       "      <td>10.680000</td>\n",
       "      <td>10.700001</td>\n",
       "      <td>11.080001</td>\n",
       "      <td>10.620001</td>\n",
       "      <td>485034</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-23</th>\n",
       "      <td>00981</td>\n",
       "      <td>10.500001</td>\n",
       "      <td>10.800000</td>\n",
       "      <td>11.160001</td>\n",
       "      <td>10.500001</td>\n",
       "      <td>1361470</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "             code       open      close       high        low      vol\n",
       "datetime                                                              \n",
       "2017-10-27  00981  10.800000  11.040001  11.200001  10.780001   613583\n",
       "2017-10-26  00981  10.840000  10.760000  11.140000  10.700001   387966\n",
       "2017-10-25  00981  10.820001  10.840000  10.980000  10.680000   258851\n",
       "2017-10-24  00981  10.680000  10.700001  11.080001  10.620001   485034\n",
       "2017-10-23  00981  10.500001  10.800000  11.160001  10.500001  1361470"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#港股数据, 设置asset='X'\n",
    "df = ts.bar('00981', conn=cons, asset='X', start_date='2016-01-01', end_date='')\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "6、期货数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "      <th>avg_price</th>\n",
       "      <th>position</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-30</th>\n",
       "      <td>CU1801</td>\n",
       "      <td>53600.0</td>\n",
       "      <td>53730.0</td>\n",
       "      <td>53770.0</td>\n",
       "      <td>53250.0</td>\n",
       "      <td>57106</td>\n",
       "      <td>53463.21875</td>\n",
       "      <td>132312</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-27</th>\n",
       "      <td>CU1801</td>\n",
       "      <td>54700.0</td>\n",
       "      <td>53970.0</td>\n",
       "      <td>54880.0</td>\n",
       "      <td>53850.0</td>\n",
       "      <td>120542</td>\n",
       "      <td>54340.00000</td>\n",
       "      <td>129300</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-26</th>\n",
       "      <td>CU1801</td>\n",
       "      <td>54880.0</td>\n",
       "      <td>54780.0</td>\n",
       "      <td>55130.0</td>\n",
       "      <td>54650.0</td>\n",
       "      <td>90966</td>\n",
       "      <td>54870.00000</td>\n",
       "      <td>129132</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-25</th>\n",
       "      <td>CU1801</td>\n",
       "      <td>55570.0</td>\n",
       "      <td>54570.0</td>\n",
       "      <td>55650.0</td>\n",
       "      <td>54200.0</td>\n",
       "      <td>125144</td>\n",
       "      <td>54880.00000</td>\n",
       "      <td>128514</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-24</th>\n",
       "      <td>CU1801</td>\n",
       "      <td>54700.0</td>\n",
       "      <td>55520.0</td>\n",
       "      <td>55880.0</td>\n",
       "      <td>54630.0</td>\n",
       "      <td>108282</td>\n",
       "      <td>55360.00000</td>\n",
       "      <td>133424</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "              code     open    close     high      low     vol    avg_price  \\\n",
       "datetime                                                                      \n",
       "2017-10-30  CU1801  53600.0  53730.0  53770.0  53250.0   57106  53463.21875   \n",
       "2017-10-27  CU1801  54700.0  53970.0  54880.0  53850.0  120542  54340.00000   \n",
       "2017-10-26  CU1801  54880.0  54780.0  55130.0  54650.0   90966  54870.00000   \n",
       "2017-10-25  CU1801  55570.0  54570.0  55650.0  54200.0  125144  54880.00000   \n",
       "2017-10-24  CU1801  54700.0  55520.0  55880.0  54630.0  108282  55360.00000   \n",
       "\n",
       "            position  \n",
       "datetime              \n",
       "2017-10-30    132312  \n",
       "2017-10-27    129300  \n",
       "2017-10-26    129132  \n",
       "2017-10-25    128514  \n",
       "2017-10-24    133424  "
      ]
     },
     "execution_count": 18,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#期货数据, 设置asset='X'\n",
    "df = ts.bar('CU1801', conn=cons, asset='X', start_date='2016-01-01', end_date='')\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "7、美股数据"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>code</th>\n",
       "      <th>open</th>\n",
       "      <th>close</th>\n",
       "      <th>high</th>\n",
       "      <th>low</th>\n",
       "      <th>vol</th>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>datetime</th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "      <th></th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>2017-10-27</th>\n",
       "      <td>BABA</td>\n",
       "      <td>173.190002</td>\n",
       "      <td>176.149994</td>\n",
       "      <td>177.000000</td>\n",
       "      <td>171.110001</td>\n",
       "      <td>19676631</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-26</th>\n",
       "      <td>BABA</td>\n",
       "      <td>170.619995</td>\n",
       "      <td>170.320007</td>\n",
       "      <td>171.449997</td>\n",
       "      <td>168.580002</td>\n",
       "      <td>13447225</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-25</th>\n",
       "      <td>BABA</td>\n",
       "      <td>174.690002</td>\n",
       "      <td>170.220001</td>\n",
       "      <td>175.440002</td>\n",
       "      <td>169.300003</td>\n",
       "      <td>18093552</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-24</th>\n",
       "      <td>BABA</td>\n",
       "      <td>174.000000</td>\n",
       "      <td>173.699997</td>\n",
       "      <td>175.979996</td>\n",
       "      <td>173.259995</td>\n",
       "      <td>11937219</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2017-10-23</th>\n",
       "      <td>BABA</td>\n",
       "      <td>177.800003</td>\n",
       "      <td>173.130005</td>\n",
       "      <td>178.009995</td>\n",
       "      <td>173.050003</td>\n",
       "      <td>17590402</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            code        open       close        high         low       vol\n",
       "datetime                                                                  \n",
       "2017-10-27  BABA  173.190002  176.149994  177.000000  171.110001  19676631\n",
       "2017-10-26  BABA  170.619995  170.320007  171.449997  168.580002  13447225\n",
       "2017-10-25  BABA  174.690002  170.220001  175.440002  169.300003  18093552\n",
       "2017-10-24  BABA  174.000000  173.699997  175.979996  173.259995  11937219\n",
       "2017-10-23  BABA  177.800003  173.130005  178.009995  173.050003  17590402"
      ]
     },
     "execution_count": 20,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#美股数据, 设置asset='X'\n",
    "df = ts.bar('BABA', conn=cons, asset='X', start_date='2016-01-01', end_date='')\n",
    "df.head(5)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "8,股票tick"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {
    "scrolled": true
   },
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>datetime</th>\n",
       "      <th>price</th>\n",
       "      <th>vol</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.87</td>\n",
       "      <td>1108</td>\n",
       "      <td>2</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.88</td>\n",
       "      <td>302</td>\n",
       "      <td>0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.86</td>\n",
       "      <td>1759</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.86</td>\n",
       "      <td>24</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.86</td>\n",
       "      <td>26</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.85</td>\n",
       "      <td>60</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.85</td>\n",
       "      <td>141</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>405</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>148</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>60</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.85</td>\n",
       "      <td>76</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>303</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.85</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>60</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.85</td>\n",
       "      <td>5</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>11</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>58</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2017-10-26 09:30</td>\n",
       "      <td>12.84</td>\n",
       "      <td>120</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2017-10-26 09:31</td>\n",
       "      <td>12.84</td>\n",
       "      <td>7</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2017-10-26 09:31</td>\n",
       "      <td>12.84</td>\n",
       "      <td>10</td>\n",
       "      <td>1</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "            datetime  price   vol  type\n",
       "0   2017-10-26 09:30  12.87  1108     2\n",
       "1   2017-10-26 09:30  12.88   302     0\n",
       "2   2017-10-26 09:30  12.86  1759     1\n",
       "3   2017-10-26 09:30  12.86    24     1\n",
       "4   2017-10-26 09:30  12.86    26     1\n",
       "5   2017-10-26 09:30  12.85    60     1\n",
       "6   2017-10-26 09:30  12.85   141     1\n",
       "7   2017-10-26 09:30  12.84   405     1\n",
       "8   2017-10-26 09:30  12.84   148     1\n",
       "9   2017-10-26 09:30  12.84    60     1\n",
       "10  2017-10-26 09:30  12.85    76     1\n",
       "11  2017-10-26 09:30  12.84   303     1\n",
       "12  2017-10-26 09:30  12.85    10     1\n",
       "13  2017-10-26 09:30  12.84    60     1\n",
       "14  2017-10-26 09:30  12.85     5     1\n",
       "15  2017-10-26 09:30  12.84    11     1\n",
       "16  2017-10-26 09:30  12.84    58     1\n",
       "17  2017-10-26 09:30  12.84   120     1\n",
       "18  2017-10-26 09:31  12.84     7     1\n",
       "19  2017-10-26 09:31  12.84    10     1"
      ]
     },
     "execution_count": 23,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#股票tick,type:买卖方向，0-买入 1-卖出 2-集合竞价成交\n",
    "df = ts.tick('600000', conn=cons, date='2017-10-26')\n",
    "df.head(20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "9,期货tick"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>price</th>\n",
       "      <th>vol</th>\n",
       "      <th>oi_change</th>\n",
       "      <th>type</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2017-10-25 20:59:00</td>\n",
       "      <td>55570.0</td>\n",
       "      <td>26</td>\n",
       "      <td>18</td>\n",
       "      <td>开仓</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2017-10-25 21:00:00</td>\n",
       "      <td>55600.0</td>\n",
       "      <td>28</td>\n",
       "      <td>6</td>\n",
       "      <td>多开</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2017-10-25 21:00:01</td>\n",
       "      <td>55620.0</td>\n",
       "      <td>26</td>\n",
       "      <td>-6</td>\n",
       "      <td>空平</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2017-10-25 21:00:01</td>\n",
       "      <td>55610.0</td>\n",
       "      <td>78</td>\n",
       "      <td>0</td>\n",
       "      <td>空换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2017-10-25 21:00:02</td>\n",
       "      <td>55610.0</td>\n",
       "      <td>50</td>\n",
       "      <td>0</td>\n",
       "      <td>多换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2017-10-25 21:00:02</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>空换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2017-10-25 21:00:03</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>空换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2017-10-25 21:00:03</td>\n",
       "      <td>55600.0</td>\n",
       "      <td>20</td>\n",
       "      <td>12</td>\n",
       "      <td>多开</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2017-10-25 21:00:04</td>\n",
       "      <td>55600.0</td>\n",
       "      <td>12</td>\n",
       "      <td>10</td>\n",
       "      <td>空开</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2017-10-25 21:00:04</td>\n",
       "      <td>55600.0</td>\n",
       "      <td>4</td>\n",
       "      <td>0</td>\n",
       "      <td>空换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2017-10-25 21:00:05</td>\n",
       "      <td>55590.0</td>\n",
       "      <td>6</td>\n",
       "      <td>0</td>\n",
       "      <td>空换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2017-10-25 21:00:05</td>\n",
       "      <td>55590.0</td>\n",
       "      <td>2</td>\n",
       "      <td>2</td>\n",
       "      <td>双开</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2017-10-25 21:00:06</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>10</td>\n",
       "      <td>2</td>\n",
       "      <td>空开</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2017-10-25 21:00:07</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>空换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2017-10-25 21:00:08</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>2</td>\n",
       "      <td>0</td>\n",
       "      <td>多换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2017-10-25 21:00:09</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>4</td>\n",
       "      <td>-2</td>\n",
       "      <td>多平</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2017-10-25 21:00:09</td>\n",
       "      <td>55590.0</td>\n",
       "      <td>8</td>\n",
       "      <td>0</td>\n",
       "      <td>多换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2017-10-25 21:00:10</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>多换</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2017-10-25 21:00:10</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>4</td>\n",
       "      <td>4</td>\n",
       "      <td>双开</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2017-10-25 21:00:11</td>\n",
       "      <td>55580.0</td>\n",
       "      <td>10</td>\n",
       "      <td>0</td>\n",
       "      <td>空换</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "</div>"
      ],
      "text/plain": [
       "                  date    price  vol  oi_change type\n",
       "0  2017-10-25 20:59:00  55570.0   26         18   开仓\n",
       "1  2017-10-25 21:00:00  55600.0   28          6   多开\n",
       "2  2017-10-25 21:00:01  55620.0   26         -6   空平\n",
       "3  2017-10-25 21:00:01  55610.0   78          0   空换\n",
       "4  2017-10-25 21:00:02  55610.0   50          0   多换\n",
       "5  2017-10-25 21:00:02  55580.0    2          0   空换\n",
       "6  2017-10-25 21:00:03  55580.0   10          0   空换\n",
       "7  2017-10-25 21:00:03  55600.0   20         12   多开\n",
       "8  2017-10-25 21:00:04  55600.0   12         10   空开\n",
       "9  2017-10-25 21:00:04  55600.0    4          0   空换\n",
       "10 2017-10-25 21:00:05  55590.0    6          0   空换\n",
       "11 2017-10-25 21:00:05  55590.0    2          2   双开\n",
       "12 2017-10-25 21:00:06  55580.0   10          2   空开\n",
       "13 2017-10-25 21:00:07  55580.0    2          0   空换\n",
       "14 2017-10-25 21:00:08  55580.0    2          0   多换\n",
       "15 2017-10-25 21:00:09  55580.0    4         -2   多平\n",
       "16 2017-10-25 21:00:09  55590.0    8          0   多换\n",
       "17 2017-10-25 21:00:10  55580.0   10          0   多换\n",
       "18 2017-10-25 21:00:10  55580.0    4          4   双开\n",
       "19 2017-10-25 21:00:11  55580.0   10          0   空换"
      ]
     },
     "execution_count": 26,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#期货tick,type:买卖方向，0:开仓  1:多开   -1:空开\n",
    "df = ts.tick('CU1801', conn=cons, asset='X', date='2017-10-25')\n",
    "df.head(20)"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# 沪深港通资金流向\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 32,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "<div>\n",
       "<style>\n",
       "    .dataframe thead tr:only-child th {\n",
       "        text-align: right;\n",
       "    }\n",
       "\n",
       "    .dataframe thead th {\n",
       "        text-align: left;\n",
       "    }\n",
       "\n",
       "    .dataframe tbody tr th {\n",
       "        vertical-align: top;\n",
       "    }\n",
       "</style>\n",
       "<table border=\"1\" class=\"dataframe\">\n",
       "  <thead>\n",
       "    <tr style=\"text-align: right;\">\n",
       "      <th></th>\n",
       "      <th>date</th>\n",
       "      <th>ggt_ss</th>\n",
       "      <th>ggt_sz</th>\n",
       "      <th>hgt</th>\n",
       "      <th>sgt</th>\n",
       "      <th>north_money</th>\n",
       "      <th>south_money</th>\n",
       "    </tr>\n",
       "  </thead>\n",
       "  <tbody>\n",
       "    <tr>\n",
       "      <th>697</th>\n",
       "      <td>2017-10-27</td>\n",
       "      <td>2949.0</td>\n",
       "      <td>1147.0</td>\n",
       "      <td>127.00</td>\n",
       "      <td>215.00</td>\n",
       "      <td>342.00</td>\n",
       "      <td>4096.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>696</th>\n",
       "      <td>2017-10-26</td>\n",
       "      <td>2057.0</td>\n",
       "      <td>1170.0</td>\n",
       "      <td>1445.83</td>\n",
       "      <td>241.66</td>\n",
       "      <td>1687.49</td>\n",
       "      <td>3227.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>695</th>\n",
       "      <td>2017-10-25</td>\n",
       "      <td>1202.0</td>\n",
       "      <td>614.0</td>\n",
       "      <td>287.37</td>\n",
       "      <td>328.13</td>\n",
       "      <td>615.50</td>\n",
       "      <td>1816.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>694</th>\n",
       "      <td>2017-10-24</td>\n",
       "      <td>1039.0</td>\n",
       "      <td>682.0</td>\n",
       "      <td>-2207.21</td>\n",
       "      <td>-943.46</td>\n",
       "      <td>-3150.67</td>\n",
       "      <td>1721.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>693</th>\n",
       "      <td>2017-10-23</td>\n",
       "      <td>1233.0</td>\n",
       "      <td>1051.0</td>\n",
       "      <td>-1183.63</td>\n",
       "      <td>-190.19</td>\n",
       "      <td>-1373.82</td>\n",
       "      <td>2284.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>692</th>\n",
       "      <td>2017-10-20</td>\n",
       "      <td>833.0</td>\n",
       "      <td>504.0</td>\n",
       "      <td>-126.00</td>\n",
       "      <td>91.00</td>\n",
       "      <td>-35.00</td>\n",
       "      <td>1337.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>691</th>\n",
       "      <td>2017-10-19</td>\n",
       "      <td>1809.0</td>\n",
       "      <td>673.0</td>\n",
       "      <td>-94.61</td>\n",
       "      <td>167.70</td>\n",
       "      <td>73.09</td>\n",
       "      <td>2482.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>690</th>\n",
       "      <td>2017-10-18</td>\n",
       "      <td>1464.0</td>\n",
       "      <td>736.0</td>\n",
       "      <td>-650.93</td>\n",
       "      <td>223.47</td>\n",
       "      <td>-427.46</td>\n",
       "      <td>2200.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>689</th>\n",
       "      <td>2017-10-17</td>\n",
       "      <td>867.0</td>\n",
       "      <td>762.0</td>\n",
       "      <td>218.55</td>\n",
       "      <td>1592.31</td>\n",
       "      <td>1810.86</td>\n",
       "      <td>1629.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>688</th>\n",
       "      <td>2017-10-16</td>\n",
       "      <td>1518.0</td>\n",
       "      <td>860.0</td>\n",
       "      <td>363.99</td>\n",
       "      <td>1208.51</td>\n",
       "      <td>1572.50</td>\n",
       "      <td>2378.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>687</th>\n",
       "      <td>2017-10-13</td>\n",
       "      <td>2170.0</td>\n",
       "      <td>1079.0</td>\n",
       "      <td>-674.00</td>\n",
       "      <td>1084.00</td>\n",
       "      <td>410.00</td>\n",
       "      <td>3249.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>686</th>\n",
       "      <td>2017-10-12</td>\n",
       "      <td>1400.0</td>\n",
       "      <td>1126.0</td>\n",
       "      <td>-407.39</td>\n",
       "      <td>893.54</td>\n",
       "      <td>486.15</td>\n",
       "      <td>2526.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>685</th>\n",
       "      <td>2017-10-11</td>\n",
       "      <td>1775.0</td>\n",
       "      <td>1225.0</td>\n",
       "      <td>597.67</td>\n",
       "      <td>1147.25</td>\n",
       "      <td>1744.92</td>\n",
       "      <td>3000.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>684</th>\n",
       "      <td>2017-10-10</td>\n",
       "      <td>1518.0</td>\n",
       "      <td>777.0</td>\n",
       "      <td>2465.29</td>\n",
       "      <td>1754.27</td>\n",
       "      <td>4219.56</td>\n",
       "      <td>2295.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>683</th>\n",
       "      <td>2017-10-09</td>\n",
       "      <td>1240.0</td>\n",
       "      <td>813.0</td>\n",
       "      <td>4714.84</td>\n",
       "      <td>2968.41</td>\n",
       "      <td>7683.25</td>\n",
       "      <td>2053.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>682</th>\n",
       "      <td>2017-09-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>455.00</td>\n",
       "      <td>778.00</td>\n",
       "      <td>1233.00</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>681</th>\n",
       "      <td>2017-09-28</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-158.17</td>\n",
       "      <td>-138.14</td>\n",
       "      <td>-296.31</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>680</th>\n",
       "      <td>2017-09-27</td>\n",
       "      <td>903.0</td>\n",
       "      <td>732.0</td>\n",
       "      <td>-142.22</td>\n",
       "      <td>876.26</td>\n",
       "      <td>734.04</td>\n",
       "      <td>1635.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>679</th>\n",
       "      <td>2017-09-26</td>\n",
       "      <td>780.0</td>\n",
       "      <td>1026.0</td>\n",
       "      <td>-101.16</td>\n",
       "      <td>211.66</td>\n",
       "      <td>110.50</td>\n",
       "      <td>1806.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>678</th>\n",
       "      <td>2017-09-25</td>\n",
       "      <td>948.0</td>\n",
       "      <td>595.0</td>\n",
       "      <td>-1834.49</td>\n",
       "      <td>157.41</td>\n",
       "      <td>-1677.08</td>\n",
       "      <td>1543.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>677</th>\n",
       "      <td>2017-09-22</td>\n",
       "      <td>1165.0</td>\n",
       "      <td>804.0</td>\n",
       "      <td>-440.00</td>\n",
       "      <td>1050.00</td>\n",
       "      <td>610.00</td>\n",
       "      <td>1969.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>676</th>\n",
       "      <td>2017-09-21</td>\n",
       "      <td>1597.0</td>\n",
       "      <td>821.0</td>\n",
       "      <td>878.64</td>\n",
       "      <td>405.50</td>\n",
       "      <td>1284.14</td>\n",
       "      <td>2418.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>675</th>\n",
       "      <td>2017-09-20</td>\n",
       "      <td>1074.0</td>\n",
       "      <td>1036.0</td>\n",
       "      <td>985.18</td>\n",
       "      <td>1157.62</td>\n",
       "      <td>2142.80</td>\n",
       "      <td>2110.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>674</th>\n",
       "      <td>2017-09-19</td>\n",
       "      <td>1432.0</td>\n",
       "      <td>560.0</td>\n",
       "      <td>-88.11</td>\n",
       "      <td>330.59</td>\n",
       "      <td>242.48</td>\n",
       "      <td>1992.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>673</th>\n",
       "      <td>2017-09-18</td>\n",
       "      <td>574.0</td>\n",
       "      <td>786.0</td>\n",
       "      <td>2588.74</td>\n",
       "      <td>1905.98</td>\n",
       "      <td>4494.72</td>\n",
       "      <td>1360.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>672</th>\n",
       "      <td>2017-09-15</td>\n",
       "      <td>-157.0</td>\n",
       "      <td>801.0</td>\n",
       "      <td>203.00</td>\n",
       "      <td>-99.00</td>\n",
       "      <td>104.00</td>\n",
       "      <td>644.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>671</th>\n",
       "      <td>2017-09-14</td>\n",
       "      <td>1138.0</td>\n",
       "      <td>706.0</td>\n",
       "      <td>-235.47</td>\n",
       "      <td>387.50</td>\n",
       "      <td>152.03</td>\n",
       "      <td>1844.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>670</th>\n",
       "      <td>2017-09-13</td>\n",
       "      <td>1057.0</td>\n",
       "      <td>1241.0</td>\n",
       "      <td>-281.86</td>\n",
       "      <td>634.62</td>\n",
       "      <td>352.76</td>\n",
       "      <td>2298.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>669</th>\n",
       "      <td>2017-09-12</td>\n",
       "      <td>1472.0</td>\n",
       "      <td>692.0</td>\n",
       "      <td>1821.45</td>\n",
       "      <td>750.05</td>\n",
       "      <td>2571.50</td>\n",
       "      <td>2164.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>668</th>\n",
       "      <td>2017-09-11</td>\n",
       "      <td>752.0</td>\n",
       "      <td>291.0</td>\n",
       "      <td>1818.64</td>\n",
       "      <td>309.94</td>\n",
       "      <td>2128.58</td>\n",
       "      <td>1043.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>...</th>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "      <td>...</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>29</th>\n",
       "      <td>2014-12-30</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-630.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>-630.00</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>28</th>\n",
       "      <td>2014-12-29</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>750.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>750.00</td>\n",
       "      <td>0.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>27</th>\n",
       "      <td>2014-12-24</td>\n",
       "      <td>292.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>NaN</td>\n",
       "      <td>0.00</td>\n",
       "      <td>292.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>26</th>\n",
       "      <td>2014-12-23</td>\n",
       "      <td>516.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>653.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>653.00</td>\n",
       "      <td>516.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>25</th>\n",
       "      <td>2014-12-22</td>\n",
       "      <td>368.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1428.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1428.00</td>\n",
       "      <td>368.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>24</th>\n",
       "      <td>2014-12-19</td>\n",
       "      <td>248.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1071.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1071.00</td>\n",
       "      <td>248.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>23</th>\n",
       "      <td>2014-12-18</td>\n",
       "      <td>398.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1908.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1908.00</td>\n",
       "      <td>398.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>22</th>\n",
       "      <td>2014-12-17</td>\n",
       "      <td>330.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>648.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>648.00</td>\n",
       "      <td>330.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>21</th>\n",
       "      <td>2014-12-16</td>\n",
       "      <td>393.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1318.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1318.00</td>\n",
       "      <td>393.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>20</th>\n",
       "      <td>2014-12-15</td>\n",
       "      <td>196.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1068.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1068.00</td>\n",
       "      <td>196.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>19</th>\n",
       "      <td>2014-12-12</td>\n",
       "      <td>311.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1862.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1862.00</td>\n",
       "      <td>311.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>18</th>\n",
       "      <td>2014-12-11</td>\n",
       "      <td>483.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1074.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1074.00</td>\n",
       "      <td>483.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>17</th>\n",
       "      <td>2014-12-10</td>\n",
       "      <td>391.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1941.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1941.00</td>\n",
       "      <td>391.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>16</th>\n",
       "      <td>2014-12-09</td>\n",
       "      <td>763.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1159.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1159.00</td>\n",
       "      <td>763.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>15</th>\n",
       "      <td>2014-12-08</td>\n",
       "      <td>525.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1677.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1677.00</td>\n",
       "      <td>525.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>14</th>\n",
       "      <td>2014-12-05</td>\n",
       "      <td>1431.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2567.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2567.00</td>\n",
       "      <td>1431.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>13</th>\n",
       "      <td>2014-12-04</td>\n",
       "      <td>415.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3521.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3521.00</td>\n",
       "      <td>415.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>12</th>\n",
       "      <td>2014-12-03</td>\n",
       "      <td>457.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3861.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3861.00</td>\n",
       "      <td>457.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>11</th>\n",
       "      <td>2014-12-02</td>\n",
       "      <td>299.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3311.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3311.00</td>\n",
       "      <td>299.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>10</th>\n",
       "      <td>2014-12-01</td>\n",
       "      <td>281.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1398.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>1398.00</td>\n",
       "      <td>281.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>9</th>\n",
       "      <td>2014-11-28</td>\n",
       "      <td>293.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2345.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2345.00</td>\n",
       "      <td>293.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>8</th>\n",
       "      <td>2014-11-27</td>\n",
       "      <td>175.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2990.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2990.00</td>\n",
       "      <td>175.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>7</th>\n",
       "      <td>2014-11-26</td>\n",
       "      <td>213.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3295.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>3295.00</td>\n",
       "      <td>213.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>6</th>\n",
       "      <td>2014-11-25</td>\n",
       "      <td>155.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2853.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2853.00</td>\n",
       "      <td>155.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>5</th>\n",
       "      <td>2014-11-24</td>\n",
       "      <td>141.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6956.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>6956.00</td>\n",
       "      <td>141.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>4</th>\n",
       "      <td>2014-11-21</td>\n",
       "      <td>186.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2341.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2341.00</td>\n",
       "      <td>186.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>3</th>\n",
       "      <td>2014-11-20</td>\n",
       "      <td>196.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2276.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2276.00</td>\n",
       "      <td>196.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>2</th>\n",
       "      <td>2014-11-19</td>\n",
       "      <td>253.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2612.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>2612.00</td>\n",
       "      <td>253.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>1</th>\n",
       "      <td>2014-11-18</td>\n",
       "      <td>800.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4845.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>4845.00</td>\n",
       "      <td>800.0</td>\n",
       "    </tr>\n",
       "    <tr>\n",
       "      <th>0</th>\n",
       "      <td>2014-11-17</td>\n",
       "      <td>1768.0</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13000.00</td>\n",
       "      <td>NaN</td>\n",
       "      <td>13000.00</td>\n",
       "      <td>1768.0</td>\n",
       "    </tr>\n",
       "  </tbody>\n",
       "</table>\n",
       "<p>698 rows × 7 columns</p>\n",
       "</div>"
      ],
      "text/plain": [
       "           date  ggt_ss  ggt_sz       hgt      sgt  north_money  south_money\n",
       "697  2017-10-27  2949.0  1147.0    127.00   215.00       342.00       4096.0\n",
       "696  2017-10-26  2057.0  1170.0   1445.83   241.66      1687.49       3227.0\n",
       "695  2017-10-25  1202.0   614.0    287.37   328.13       615.50       1816.0\n",
       "694  2017-10-24  1039.0   682.0  -2207.21  -943.46     -3150.67       1721.0\n",
       "693  2017-10-23  1233.0  1051.0  -1183.63  -190.19     -1373.82       2284.0\n",
       "692  2017-10-20   833.0   504.0   -126.00    91.00       -35.00       1337.0\n",
       "691  2017-10-19  1809.0   673.0    -94.61   167.70        73.09       2482.0\n",
       "690  2017-10-18  1464.0   736.0   -650.93   223.47      -427.46       2200.0\n",
       "689  2017-10-17   867.0   762.0    218.55  1592.31      1810.86       1629.0\n",
       "688  2017-10-16  1518.0   860.0    363.99  1208.51      1572.50       2378.0\n",
       "687  2017-10-13  2170.0  1079.0   -674.00  1084.00       410.00       3249.0\n",
       "686  2017-10-12  1400.0  1126.0   -407.39   893.54       486.15       2526.0\n",
       "685  2017-10-11  1775.0  1225.0    597.67  1147.25      1744.92       3000.0\n",
       "684  2017-10-10  1518.0   777.0   2465.29  1754.27      4219.56       2295.0\n",
       "683  2017-10-09  1240.0   813.0   4714.84  2968.41      7683.25       2053.0\n",
       "682  2017-09-29     NaN     NaN    455.00   778.00      1233.00          0.0\n",
       "681  2017-09-28     NaN     NaN   -158.17  -138.14      -296.31          0.0\n",
       "680  2017-09-27   903.0   732.0   -142.22   876.26       734.04       1635.0\n",
       "679  2017-09-26   780.0  1026.0   -101.16   211.66       110.50       1806.0\n",
       "678  2017-09-25   948.0   595.0  -1834.49   157.41     -1677.08       1543.0\n",
       "677  2017-09-22  1165.0   804.0   -440.00  1050.00       610.00       1969.0\n",
       "676  2017-09-21  1597.0   821.0    878.64   405.50      1284.14       2418.0\n",
       "675  2017-09-20  1074.0  1036.0    985.18  1157.62      2142.80       2110.0\n",
       "674  2017-09-19  1432.0   560.0    -88.11   330.59       242.48       1992.0\n",
       "673  2017-09-18   574.0   786.0   2588.74  1905.98      4494.72       1360.0\n",
       "672  2017-09-15  -157.0   801.0    203.00   -99.00       104.00        644.0\n",
       "671  2017-09-14  1138.0   706.0   -235.47   387.50       152.03       1844.0\n",
       "670  2017-09-13  1057.0  1241.0   -281.86   634.62       352.76       2298.0\n",
       "669  2017-09-12  1472.0   692.0   1821.45   750.05      2571.50       2164.0\n",
       "668  2017-09-11   752.0   291.0   1818.64   309.94      2128.58       1043.0\n",
       "..          ...     ...     ...       ...      ...          ...          ...\n",
       "29   2014-12-30     NaN     NaN   -630.00      NaN      -630.00          0.0\n",
       "28   2014-12-29     NaN     NaN    750.00      NaN       750.00          0.0\n",
       "27   2014-12-24   292.0     NaN       NaN      NaN         0.00        292.0\n",
       "26   2014-12-23   516.0     NaN    653.00      NaN       653.00        516.0\n",
       "25   2014-12-22   368.0     NaN   1428.00      NaN      1428.00        368.0\n",
       "24   2014-12-19   248.0     NaN   1071.00      NaN      1071.00        248.0\n",
       "23   2014-12-18   398.0     NaN   1908.00      NaN      1908.00        398.0\n",
       "22   2014-12-17   330.0     NaN    648.00      NaN       648.00        330.0\n",
       "21   2014-12-16   393.0     NaN   1318.00      NaN      1318.00        393.0\n",
       "20   2014-12-15   196.0     NaN   1068.00      NaN      1068.00        196.0\n",
       "19   2014-12-12   311.0     NaN   1862.00      NaN      1862.00        311.0\n",
       "18   2014-12-11   483.0     NaN   1074.00      NaN      1074.00        483.0\n",
       "17   2014-12-10   391.0     NaN   1941.00      NaN      1941.00        391.0\n",
       "16   2014-12-09   763.0     NaN   1159.00      NaN      1159.00        763.0\n",
       "15   2014-12-08   525.0     NaN   1677.00      NaN      1677.00        525.0\n",
       "14   2014-12-05  1431.0     NaN   2567.00      NaN      2567.00       1431.0\n",
       "13   2014-12-04   415.0     NaN   3521.00      NaN      3521.00        415.0\n",
       "12   2014-12-03   457.0     NaN   3861.00      NaN      3861.00        457.0\n",
       "11   2014-12-02   299.0     NaN   3311.00      NaN      3311.00        299.0\n",
       "10   2014-12-01   281.0     NaN   1398.00      NaN      1398.00        281.0\n",
       "9    2014-11-28   293.0     NaN   2345.00      NaN      2345.00        293.0\n",
       "8    2014-11-27   175.0     NaN   2990.00      NaN      2990.00        175.0\n",
       "7    2014-11-26   213.0     NaN   3295.00      NaN      3295.00        213.0\n",
       "6    2014-11-25   155.0     NaN   2853.00      NaN      2853.00        155.0\n",
       "5    2014-11-24   141.0     NaN   6956.00      NaN      6956.00        141.0\n",
       "4    2014-11-21   186.0     NaN   2341.00      NaN      2341.00        186.0\n",
       "3    2014-11-20   196.0     NaN   2276.00      NaN      2276.00        196.0\n",
       "2    2014-11-19   253.0     NaN   2612.00      NaN      2612.00        253.0\n",
       "1    2014-11-18   800.0     NaN   4845.00      NaN      4845.00        800.0\n",
       "0    2014-11-17  1768.0     NaN  13000.00      NaN     13000.00       1768.0\n",
       "\n",
       "[698 rows x 7 columns]"
      ]
     },
     "execution_count": 32,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#沪/深港通每日资金流向(南向/北向资金)\n",
    "df = ts.moneyflow_hsgt()\n",
    "df.sort_values('date', ascending=False)"
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.1"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
